﻿namespace Skymate.Mvc
{
    using System.Reflection;
    using System.Web;
    using System.Web.Mvc;

    using Castle.MicroKernel.Registration;

    using Skymate.Modules;
    using Skymate.Mvc.Controllers;
    using Skymate.Services.Authentication;

    [DependsOn(typeof(AbpKernelModule))]
    public class SkymateMvcModule: AbpModule
    {
        /// <inheritdoc/>
        public override void PreInitialize()
        {

            IocManager.AddConventionalRegistrar(new ControllerConventionalRegistrar());
        }

        /// <inheritdoc/>
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(IocManager.IocContainer.Kernel));
         
            
            IocManager.Register<IWorkContext,WebWorkContext>();
            IocManager.Register<IAuthenticationService,FormsAuthenticationService>();
            IocManager.IocContainer.Register(
                Component.For<HttpContextBase>()
                .UsingFactoryMethod(u=> new HttpContextWrapper(HttpContext.Current))
                    .LifestyleTransient()
                );

        }
    }
}